package Week.Double004;

import java.util.HashMap;
import java.util.Map;

/**
 * @program Leetcode
 * @description:
 * @author: lishangsheng
 * @create: 2019/07/16 10:41
 */
public class problem01 {
    public int numberOfDays(int Y, int M) {
        Map<Integer,Integer> map=new HashMap<>();
        for(int i=1;i<13;i++){
            if(i==2){
                continue;
            }
            if(i==1||i==3||i==5||i==7||i==8||i==10||i==12){
                map.put(i,31);
            }else{
                map.put(i,30);
            }
        }
        if(M!=2){
            return map.get(M);
        }
        if(Y%100==0){
            if(Y%400==0){
                return 29;
            }
        }else {
            if(Y%4==0){
                return 29;
            }
        }
        return 28;
    }


    public int numberOfDays2(int Y, int M) {
        if (Y % 400 == 0 || (Y % 100 != 0 && Y % 4 == 0)) {
            if (M == 2) return 29;
        }
        int[] mon = new int[] {31,28,31,30,31,30,31,31,30,31,30,31};
        return mon[M - 1];
    }
}
